<style>
    input[type=color],
    input[type=date],
    input[type=datetime-local],
    input[type=datetime],
    input[type=email],
    input[type=month],
    input[type=number],
    input[type=password],
    input[type=search],
    input[type=tel],
    input[type=text],
    input[type=time],
    input[type=url],
    input[type=week],
    select,
    textarea {
        width: 100%;
        height: 1.47058824em;
        line-height: 1.47058824;
        -webkit-appearance: none;
        padding: 0;
        margin-bottom: 0;
        background-color: transparent;
        border: none;
        border-radius: 0;
        outline: none;
        font-size: inherit;
        color: inherit;
        -webkit-user-select: text;
    }
</style>
<script type="text/x-template" id='warn'>
    <div>
        <div style="margin-top:0;" class="weui-cells weui-cells_form">
            <div class="weui-cells__title">设置提醒</div>
            <div class="weui-cell weui-cell_switch">
                <div class="weui-cell__bd">提醒开关</div>
                <div class="weui-cell__ft">
                    <input v-model="warn.iswarn" class="weui-switch" type="checkbox">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">提醒时间</label></div>
                <div class="weui-cell__bd">
                    <input @click="showTime()" v-model="warn.warntime" readonly class="weui-input" type="text" placeholder="请选择时间">
                </div>
            </div>
        </div>
        <div class="weui-btn-area">
            <a class="weui-btn weui-btn_primary" @click="setWarn()" id="showTooltips">确定</a>
        </div>
    </div>
</script>
<script>
    var warn = Vue.component('warn', {
        template: '#warn',
        data: function () {
            return {
                warn: {
                    iswarn: false,
                    warntime: ''
                },
                userinfo:{}
            }
        },
        created: function () {
            window.v = this;
            this.getUserinfo();
        },
        methods: {
            getUserinfo: function () {
                var self = this;
                http({
                    url: baseUrl + 'getuserinfo',
                }).then(function (res) {
                    res = res.data;
                    self.userinfo = res.data;
                    self.warn.iswarn = res.data.iswarn==1?true:false;
                    self.warn.warntime = res.data.warntime;
                })
            },
            showTime: function () {
                var self = this;
                var hour = [];
                for (var i = 5; i <= 7; i++) {
                    hour.push({
                        label: i + '时',
                        value: i
                    });
                }
                var minutes = [];
                for (var i = 0; i <= 59; i++) {
                    minutes.push({
                        label: i + '分',
                        value: i
                    });
                }
                weui.picker(hour, minutes, {
                    defaultValue: [7, 0],
                    onChange: function (result) {
                        console.log(result);
                    },
                    onConfirm: function (result) {
                        self.warn.warntime = result[0].value + ':' + result[1].value;
                    },
                });
            },
            setWarn: function () {
                var self = this;
                http({
                    url: baseUrl + 'setwarn',
                    method: 'post',
                    data: self.warn
                }).then(function (res) {
                    res = res.data;
                    weui.alert(res.message,function(){
                        self.$router.go(-1);
                    });
                })
            }
        }
    });
</script>